/**
 * ==================================================================   
 * @Title: SessionFilter.java
 * ==================================================================  
 * @Created 2016-1-14 上午11:31:21  by lianglm
 * ================================================================== 
 * @version V1.0 
 * Copyright (c) Zailing Technology Inc ZheJiang, 2015-2017
 * ================================================================== 
 * 浙江新再灵科技股份有限公司拥有该文件的使用、复制、修改和分发的许可权
 * 如果你想得到更多信息，请访问 <http://www.zailingtech.com>
 *
 * Zailing Technology Inc ZheJiang owns permission to use, copy, modify and 
 * distribute this documentation.
 * For more information on SessionFilter.java, please 
 * see <http://www.zailingtech.com>.  
 * ================================================================== 
 */
package com.common.filter;

import java.io.IOException;
import java.io.PrintWriter;
import java.util.List;

import javax.servlet.Filter;
import javax.servlet.FilterChain;
import javax.servlet.FilterConfig;
import javax.servlet.ServletException;
import javax.servlet.ServletRequest;
import javax.servlet.ServletResponse;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;

import com.wpd.bo.WpdUser;

public class SessionFilter implements Filter {

    @Override
	public void destroy() {
		// TODO Auto-generated method stub

	}

	/* (non-Javadoc)
	 * @see javax.servlet.Filter#doFilter(javax.servlet.ServletRequest, javax.servlet.ServletResponse, javax.servlet.FilterChain)
	 */
	@Override
	public void doFilter(ServletRequest arg0, ServletResponse arg1,
			FilterChain arg2) throws IOException, ServletException {
		// TODO Auto-generated method stub
		 HttpServletRequest req = (HttpServletRequest) arg0;
		 HttpServletResponse res = (HttpServletResponse) arg1;
		 HttpSession session = req.getSession();
		 WpdUser user=(WpdUser)session.getAttribute("user_info");
         
         if(user == null 
        		 && !"/WPD/login/userLogin.do".equals(req.getRequestURI()) 
        		 && !"/WPD/login/loginOut.do".equals(req.getRequestURI())){
        	 throw new RuntimeException("会话已过期");
         }else{
        	         arg2.doFilter(arg0, arg1);
         }
	}

	/* (non-Javadoc)
	 * @see javax.servlet.Filter#init(javax.servlet.FilterConfig)
	 */
	@Override
	public void init(FilterConfig arg0) throws ServletException {
		// TODO Auto-generated method stub

	}

}
